package com.chen.controller;

import com.chen.dao.pojo.Coach;
import com.chen.service.CoachService;
import com.chen.vo.Result;
import com.chen.vo.param.CoachParam;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author:chenao
 * @DATE:2022/3/19 20:26
 */
@RestController
@RequestMapping("coach")
public class CoachController {

    @Autowired
    private CoachService coachService;

    /**
     * 单独上传头像使用，修改头像
     * @param file
     * @param params
     * @return
     */
    @PostMapping("upload")
    public Result updateCoach(@RequestParam("avatar") MultipartFile file, @RequestParam Map<String, String> params){
        return coachService.uploadAvatar(file,params);
    }

    /**
     * 通过id获取单个教练的资料
     * @param param
     * @return
     */
    @PostMapping("detail")
    public Result getCoachInfoById(@RequestBody CoachParam param){
        return Result.success(coachService.findCoachById(param.getId()));
    }

    /**
     * 教练登录
     * @param param
     * @return
     */
    @PostMapping("login")
    public Result login(@RequestBody CoachParam param){
        return coachService.login(param);
    }

    /**
     * 教练编辑资料，除头像外
     * @param param
     * @return
     */
    @PostMapping("edit")
    public Result editCoachInfo(@RequestBody CoachParam param){
        return coachService.updateCoach(param);
    }

    /**
     * 查询教练列表，用户首页和列表展示
     * @param param
     * @return
     */
    @PostMapping("list")
    public Result listCoach(@RequestBody CoachParam param){
        return coachService.listCoach(param);
    }

    /**
     * 用户对教练评价几颗星，保存并计算评分
     * @param param
     * @return
     */
    @PostMapping("rate")
    public Result publishRate(@RequestBody CoachParam param){
        return coachService.updateRate(param);
    }

    /**
     * 发表评论
     * @param param
     * @return
     */
    @PostMapping("comment")
    public Result publishComment(@RequestBody CoachParam param){
        return coachService.publishComment(param);
    }

    /**
     * 评论列表
     * @param param
     * @return
     */
    @PostMapping("comment/list")
    public Result listComment(@RequestBody CoachParam param){
        return coachService.listComment(param);
    }

    /**
     * 教练上课概况，本月、今天、剩余多少课
     * @param param
     * @return
     */
    @PostMapping("record")
    public Result coachRecord(@RequestBody CoachParam param){
        return coachService.coachRecord(param);
    }

    /**
     * 教练排行榜
     * @param param
     * @return
     */
    @PostMapping("rank")
    public Result coachRank(@RequestBody CoachParam param){
        return coachService.coachRank(param);
    }
}
